package org.atlantis.grosbeak.cable;

import javax.servlet.ServletContext;

import org.atlantis.grosbeak.cable.meta.ApplicationAware;
import org.atlantis.grosbeak.castor.Castors;

class DefaultApplicationAware implements ApplicationAware {

	private ServletContext sc;

	public DefaultApplicationAware(ServletContext sc) {
		this.sc = sc;
	}

	public Object getAttr(String key) {
		return sc.getAttribute(key);
	}

	public <T> T getAttr(Class<T> type, String key) {
		Object value = sc.getAttribute(key);
		T result = Castors.me().castTo(value, type);
		return result;
	}

	public ServletContext getSelf() {
		return sc;
	}

	public void setAttr(String key, Object value) {
		sc.setAttribute(key, value);
	}
}
